package com.dljd.javase.t12;

import java.util.ArrayList;

public class ArrayListDemo {
    public static void main(String[] args) {
        final MyArray  m=new MyArray();
        for (int i = 0; i <10; i++) {
            Thread t=  new Thread(){
                public  void run() {
                    for(int n=0;n<100;n++){
                        m.addElement(n);
                    }
                }
            };
            t.start();
        }

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("ArrayList:"+m.getSize());
    }
}
class MyArray {
     ArrayList n1=new ArrayList();

    public synchronized void addElement(Object o){
        n1.add(o);
    }
    public int getSize(){
        return n1.size();
    }
}
